//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "BlackVanillaOptionPricer.h"
using namespace Cephei::QL::Cashflows;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Cashflows/VanillaOptionPricer.h>
using namespace Cephei::QL::Times;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Cashflows::CBlackVanillaOptionPricer::CBlackVanillaOptionPricer (boost::shared_ptr<QuantLib::BlackVanillaOptionPricer>& childNative, Object^ owner) : CVanillaOptionPricer(CBlackVanillaOptionPricer::typeid)
{
#ifdef HANDLE
	_phBlackVanillaOptionPricer = NULL;
#endif
	_ppBlackVanillaOptionPricer = &childNative;
    _ppVanillaOptionPricer = new boost::shared_ptr<QuantLib::VanillaOptionPricer> (boost::dynamic_pointer_cast<QuantLib::VanillaOptionPricer> (*_ppBlackVanillaOptionPricer));
}
Cephei::QL::Cashflows::CBlackVanillaOptionPricer::CBlackVanillaOptionPricer (QuantLib::BlackVanillaOptionPricer& childNative, Object^ owner) : CVanillaOptionPricer(CBlackVanillaOptionPricer::typeid)
{
#ifdef HANDLE
	_phBlackVanillaOptionPricer = NULL;
#endif
	_ppBlackVanillaOptionPricer = new boost::shared_ptr<QuantLib::BlackVanillaOptionPricer> (&childNative);
    _ppVanillaOptionPricer = new boost::shared_ptr<QuantLib::VanillaOptionPricer> (boost::dynamic_pointer_cast<QuantLib::VanillaOptionPricer> (*_ppBlackVanillaOptionPricer));
    _BlackVanillaOptionPricerOwner = owner;
    _VanillaOptionPricerOwner = owner;
}

Cephei::QL::Cashflows::CBlackVanillaOptionPricer::CBlackVanillaOptionPricer (CBlackVanillaOptionPricer^ copy) : CVanillaOptionPricer(CBlackVanillaOptionPricer::typeid)
{
#ifdef HANDLE
	_phBlackVanillaOptionPricer = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppBlackVanillaOptionPricer = new boost::shared_ptr<QuantLib::BlackVanillaOptionPricer> (copy->GetShared());
        _ppVanillaOptionPricer = new boost::shared_ptr<QuantLib::VanillaOptionPricer> (boost::dynamic_pointer_cast<QuantLib::VanillaOptionPricer> (*_ppBlackVanillaOptionPricer));
    }
}
Cephei::QL::Cashflows::CBlackVanillaOptionPricer::CBlackVanillaOptionPricer (System::Type^ t) : CVanillaOptionPricer(CBlackVanillaOptionPricer::typeid)
{
#ifdef HANDLE
	_phBlackVanillaOptionPricer = NULL;
#endif
	if (!t->IsSubclassOf(CBlackVanillaOptionPricer::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Cashflows::CBlackVanillaOptionPricer::CBlackVanillaOptionPricer (QuantLib::Handle<QuantLib::BlackVanillaOptionPricer>& childNative, Object^ owner)  : CVanillaOptionPricer(CBlackVanillaOptionPricer::typeid)
{
	_phBlackVanillaOptionPricer = &childNative;
	_ppBlackVanillaOptionPricer = &static_cast<boost::shared_ptr<QuantLib::BlackVanillaOptionPricer>>(childNative.currentLink());
    _ppVanillaOptionPricer = new boost::shared_ptr<QuantLib::VanillaOptionPricer> (boost::dynamic_pointer_cast<QuantLib::VanillaOptionPricer> (*_ppBlackVanillaOptionPricer));
    _BlackVanillaOptionPricerOwner = owner;
}
Cephei::QL::Cashflows::CBlackVanillaOptionPricer::CBlackVanillaOptionPricer (QuantLib::Handle<QuantLib::BlackVanillaOptionPricer> childNative)  : CVanillaOptionPricer(CBlackVanillaOptionPricer::typeid)
{
	_phBlackVanillaOptionPricer = &childNative;
	_ppBlackVanillaOptionPricer = &static_cast<boost::shared_ptr<QuantLib::BlackVanillaOptionPricer>>(childNative.currentLink());
    _ppVanillaOptionPricer = new boost::shared_ptr<QuantLib::VanillaOptionPricer> (boost::dynamic_pointer_cast<QuantLib::VanillaOptionPricer> (*_ppBlackVanillaOptionPricer));
}
#endif
#ifdef STRUCT
Cephei::QL::Cashflows::CBlackVanillaOptionPricer::CBlackVanillaOptionPricer (QuantLib::BlackVanillaOptionPricer childNative)  : CVanillaOptionPricer(CBlackVanillaOptionPricer::typeid)
{
#ifdef HANDLE
	_phBlackVanillaOptionPricer = NULL;
#endif
	_ppBlackVanillaOptionPricer = new boost::shared_ptr<QuantLib::BlackVanillaOptionPricer> (new QuantLib::BlackVanillaOptionPricer (childNative));
    _ppVanillaOptionPricer = new boost::shared_ptr<QuantLib::VanillaOptionPricer> (boost::dynamic_pointer_cast<QuantLib::VanillaOptionPricer> (*_ppBlackVanillaOptionPricer));
}
#endif

Cephei::QL::Cashflows::CBlackVanillaOptionPricer::~CBlackVanillaOptionPricer ()
{
    if (_ppBlackVanillaOptionPricer != NULL)
    {
	    delete _ppBlackVanillaOptionPricer;
        _ppBlackVanillaOptionPricer = NULL;
    }
}
Cephei::QL::Cashflows::CBlackVanillaOptionPricer::!CBlackVanillaOptionPricer ()
{
    if (_ppBlackVanillaOptionPricer != NULL)
    {
	    delete _ppBlackVanillaOptionPricer;
    }
}
QuantLib::BlackVanillaOptionPricer& Cephei::QL::Cashflows::CBlackVanillaOptionPricer::GetReference ()
{
    if (_ppBlackVanillaOptionPricer == NULL) throw gcnew NativeNullException ();
	return **_ppBlackVanillaOptionPricer;
}
boost::shared_ptr<QuantLib::BlackVanillaOptionPricer>& Cephei::QL::Cashflows::CBlackVanillaOptionPricer::GetShared ()
{
    if (_ppBlackVanillaOptionPricer == NULL) throw gcnew NativeNullException ();
	return *_ppBlackVanillaOptionPricer;
}
QuantLib::BlackVanillaOptionPricer* Cephei::QL::Cashflows::CBlackVanillaOptionPricer::GetPointer ()
{
    if (_ppBlackVanillaOptionPricer == NULL) throw gcnew NativeNullException ();
	return &**_ppBlackVanillaOptionPricer;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::BlackVanillaOptionPricer>& Cephei::QL::Cashflows::CBlackVanillaOptionPricer::GetHandle ()
{
	if (_phBlackVanillaOptionPricer == NULL)
	{
		_phBlackVanillaOptionPricer = new Handle<QuantLib::BlackVanillaOptionPricer> (*_ppBlackVanillaOptionPricer);
	}
	return *_phBlackVanillaOptionPricer;
}
#endif
bool Cephei::QL::Cashflows::CBlackVanillaOptionPricer::HasNative () 
{
	return (_ppBlackVanillaOptionPricer != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

